package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.SalaryQueryObject;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("salary")
public class SalaryController {

    @Autowired
    ISalaryService salaryService;

    @RequestMapping("")
    @RequiresPermissions(value = {"工资首页","salary:index"} ,logical = Logical.OR)
    public String index(){
        return "salary/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"工资列表","salary:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(SalaryQueryObject qo){
        PageResult result = salaryService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return salaryService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"工资保存","salary:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(Salary entity){
        JSONResult result = new JSONResult();
        try{
            salaryService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
